package com.school.revervationSys.service.impl;


import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.school.revervationSys.dto.ReverVationDto;
import com.school.revervationSys.entity.Revervation;
import com.school.revervationSys.entity.User;
import com.school.revervationSys.mapper.RevervationMapper;
import com.school.revervationSys.mapper.UserMapper;
import com.school.revervationSys.service.IRevervationService;
import com.school.revervationSys.vo.RevervationVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author msj
 * @since 2024-04-13
 */
@Service
public class RevervationServiceImpl extends ServiceImpl<RevervationMapper, Revervation> implements IRevervationService {

@Autowired
private RevervationMapper revervationMapper;
@Autowired
private UserMapper userMapper;

    public boolean addRevervation(Revervation revervation) {

        return this.save(revervation);

    }

    public boolean updateRevervation(Revervation revervation) {
        return this.updateById(revervation);
    }

    public boolean delete(Integer revervationId) {

        return this.removeById(revervationId);
    }

    public boolean batchDelete(List<Integer> ids){

        return this.removeByIds(ids);
    }

    public RevervationVo revationInfo(Integer revervationId){

        Revervation byId = this.getById(revervationId);
        RevervationVo revervationVo=new RevervationVo();
        BeanUtils.copyProperties(byId,revervationVo);
        User user = userMapper.selectById(byId.getStudentId());
        BeanUtils.copyProperties(user,revervationVo);

        return revervationVo;
    }

    public  List<Revervation> revervationList(ReverVationDto param){

        List<Revervation> revervations = revervationMapper.revervationList(param);
        return revervations;
    }


}
